<?php


namespace api\web\controller;


use api\web\model\NewsModel;
use cmf\controller\RestBaseController;

class NewsController extends RestBaseController
{
    //获取新闻列表
    public function getNewsList(){
        $keyword=input('keyword','');
        $where=[];
        if($keyword){
            $where[]=['title|author','like','%'.$keyword.'%'];
        }
        //分页
        $page = input('page/d',2);
        $pageSize = input('page_size/d',2);
        $list = NewsModel::where($where)
            ->order('list_order','desc')
            ->field('id,title,image,abstract,createtime',)
            ->page($page,$pageSize)
            ->select();
        $this->success('新闻管理',$list);
    }
    //获取新闻详情
    public function getNewsInfo(){
        $id = input('id/d');
        if(empty($id)){
            $this->error('id为空');
        }
        //去除那个字段
        $list = NewsModel::withoutField('deletetime,list_order')->find($id);

        $news = NewsModel::find($id);
        if(!($news)){
            $this->error('查询失败');
        }
        //文章处理
        $content = $list['content'];
        $content1 = htmlspecialchars_decode($content);
        $list['content'] = $content1;
        $this->success('新闻详情管理',$list);
    }
}